package com.http;

import org.json.JSONArray;

import android.os.AsyncTask;

import com.android.ocean.util.net.ErrorCode;
import com.android.ocean.util.net.NetConUtil;
import com.android.ocean.util.net.ResEntity;
import com.common.method.CommonData;
import com.common.method.ServerPath;
import com.util.JsonUtil;

/**
 * 
 * @ClassName:NoReadMsgListTask
 * @Description:TODO未读消息列表
 * @author zhuw
 * @date 2013-11-2 下午9:06:01
 */
public class NoReadMsgListTask extends AsyncTask<String, Void, ResultUserList> {
	NetCallBack callBack;

	public NoReadMsgListTask(NetCallBack callBack) {
		super();
		this.callBack = callBack;
	}

	@Override
	protected ResultUserList doInBackground(String... params) {
		ResultUserList data = null;
		try {
			ResEntity re = null;

			re = NetConUtil.sendGetRequestEntity(ServerPath.NO_READ_MSG_PATH
					+ params[1]);

			if (re.code == ResEntity.S_OK) {
				data = new ResultUserList(CommonData.H_FLAG_SUCCESS, null,
						JsonUtil.parseNoReadMsgList(new JSONArray(re.jsonStr),params[0]));
			} else if (re.code == ResEntity.S_FAILED) {

				data = new ResultUserList(CommonData.H_FLAG_ERROR, "code:"
						+ re.code + "    " + re.jsonStr, null);

			} else {
				data = new ResultUserList(CommonData.H_FLAG_ERROR, "code:"
						+ re.code + ErrorCode.ERROR_MSG, null);
			}
		} catch (Exception e) {
			data = new ResultUserList(CommonData.H_FLAG_ERROR,
					ErrorCode.ERROR_MSG, null);
			e.printStackTrace();

		}
		return data;
	}

	@Override
	protected void onPostExecute(ResultUserList result) {
		if (result.flag == CommonData.H_FLAG_SUCCESS) {
			callBack.onSuccess(result.dataList);

		} else {
			callBack.onError(result.msg);
		}

	}
}
